// JavaScript Document

function letterValidation(updatePlayers)
{
	if ( (document.updatePlayers.getElementById('player1T1Letter').value==document.updatePlayers.getElementById('player2T1Letter').value)|| (document.updatePlayers.getElementById('player1T1Letter').value==document.updatePlayers.getElementById('player3T1Letter').value) || (document.updatePlayers.getElementById('player2T1Letter').value==document.updatePlayers.getElementById('player3T1Letter').value)){	
	alert('Same letter is used more than once');
	//document.updatePlayers.player1T1Letter.focus();
	return false;
	}
	else if ( (document.updatePlayers.getElementById('player1T2Letter').value==document.updatePlayers.getElementById('player2T2Letter').value)|| (document.updatePlayers.getElementById('player1T2Letter').value==document.updatePlayers.getElementById('player3T2Letter').value) || (document.updatePlayers.getElementById('player2T2Letter').value==document.updatePlayers.getElementById('player3T2Letter').value)){	
	alert('Same letter is used more than once');
	//document.updatePlayers.player1T1Letter.focus();
	return false;
	}
}

function playerValidation(updatePlayers)
{
	var players = [document.updatePlayers.getElementById('player1T1').value, document.updatePlayers.getElementById('player2T1').value,document.updatePlayers.getElementById('player3T1').value,document.updatePlayers.getElementById('player1T2').value,document.updatePlayers.getElementById('player2T2').value,document.updatePlayers.getElementById('player3T2').value];
	var count= 0;
	var i= 0;
	var j=0;
	for (i= 0; i<6; i++)
	{
		for (j=i+1; j<6; j++)
		{
			if (players[i]==players[j])
			{
				count=count+1;
			}
		}
		
	}
	if (count>=1)
		{
			alert('Same player was entered more than once');
			return false;
		}
	else 
		return true;
	
	
}

function validatePlayerUpdate(updatePlayers)
{
	if (letterValidation(updatePlayers)==false)
		return false;
	else if (playerValidation(updatePlayers)==false)
		return false;
	else 
		return true;
}

function validatePlayerAdd()
{
	if ( (document.getElementById('fname').value=="")||(document.getElementById('sname').value==""))
	{
		alert("First name and last name are required.");
		return false;
	}
	else 
		return true;

}
function validateTeamAdd()
{
	if ( (document.getElementById('team_name').value=="")||(document.getElementById('password').value=="")||(document.getElementById('division').value==""))
	{
		alert("Team name, password and division are required.");
		return false;
	}
	else 
		return true;

}